package com.usa.tool;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author YueGod
 * @since 2023/11/27
 */
public class FeishuUserJson {

    public static void main(String[] args) {
        String json = "{\n" +
                "  \"code\": 0,\n" +
                "  \"data\": {\n" +
                "    \"has_more\": false,\n" +
                "    \"items\": [\n" +
                "      {\n" +
                "        \"avatar\": {\n" +
                "          \"avatar_240\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_963d2703-24fd-48da-a701-cff18bfffdfg~?image_size=240x240&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_640\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_963d2703-24fd-48da-a701-cff18bfffdfg~?image_size=640x640&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_72\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_963d2703-24fd-48da-a701-cff18bfffdfg~?image_size=72x72&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_origin\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_963d2703-24fd-48da-a701-cff18bfffdfg~?image_size=noop&cut_type=&quality=&format=png&sticker_format=.webp\"\n" +
                "        },\n" +
                "        \"city\": \"\",\n" +
                "        \"country\": \"\",\n" +
                "        \"department_ids\": [\n" +
                "          \"f5geb5aae223eea9\",\n" +
                "          \"3g6b2f2g1b6bda3e\"\n" +
                "        ],\n" +
                "        \"description\": \"\",\n" +
                "        \"email\": \"\",\n" +
                "        \"employee_no\": \"\",\n" +
                "        \"employee_type\": 1,\n" +
                "        \"en_name\": \"\",\n" +
                "        \"enterprise_email\": \"helen@hpznt.com\",\n" +
                "        \"gender\": 0,\n" +
                "        \"is_tenant_manager\": false,\n" +
                "        \"job_title\": \"\",\n" +
                "        \"join_time\": 0,\n" +
                "        \"mobile\": \"+8615828102461\",\n" +
                "        \"mobile_visible\": true,\n" +
                "        \"name\": \"Helen\",\n" +
                "        \"open_id\": \"ou_0e17d7f26d2496f85bc65f93da0f51f9\",\n" +
                "        \"orders\": [\n" +
                "          {\n" +
                "            \"department_id\": \"f5geb5aae223eea9\",\n" +
                "            \"department_order\": 2,\n" +
                "            \"is_primary_dept\": true,\n" +
                "            \"user_order\": 0\n" +
                "          },\n" +
                "          {\n" +
                "            \"department_id\": \"3g6b2f2g1b6bda3e\",\n" +
                "            \"department_order\": 1,\n" +
                "            \"is_primary_dept\": false,\n" +
                "            \"user_order\": 0\n" +
                "          }\n" +
                "        ],\n" +
                "        \"status\": {\n" +
                "          \"is_activated\": true,\n" +
                "          \"is_exited\": false,\n" +
                "          \"is_frozen\": false,\n" +
                "          \"is_resigned\": false,\n" +
                "          \"is_unjoin\": false\n" +
                "        },\n" +
                "        \"union_id\": \"on_2b9f6f21c06468b53fceb624ebb2f682\",\n" +
                "        \"user_id\": \"eac978f1\",\n" +
                "        \"work_station\": \"\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"avatar\": {\n" +
                "          \"avatar_240\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_5a002e8f-c1d8-431c-a9da-71139f41b3cg~?image_size=240x240&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_640\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_5a002e8f-c1d8-431c-a9da-71139f41b3cg~?image_size=640x640&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_72\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_5a002e8f-c1d8-431c-a9da-71139f41b3cg~?image_size=72x72&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_origin\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_5a002e8f-c1d8-431c-a9da-71139f41b3cg~?image_size=noop&cut_type=&quality=&format=png&sticker_format=.webp\"\n" +
                "        },\n" +
                "        \"city\": \"\",\n" +
                "        \"country\": \"\",\n" +
                "        \"department_ids\": [\n" +
                "          \"f5geb5aae223eea9\"\n" +
                "        ],\n" +
                "        \"description\": \"\",\n" +
                "        \"email\": \"\",\n" +
                "        \"employee_no\": \"\",\n" +
                "        \"employee_type\": 1,\n" +
                "        \"en_name\": \"\",\n" +
                "        \"enterprise_email\": \"yolo@hpznt.com\",\n" +
                "        \"gender\": 0,\n" +
                "        \"is_tenant_manager\": false,\n" +
                "        \"job_title\": \"\",\n" +
                "        \"join_time\": 0,\n" +
                "        \"mobile\": \"+8617828414312\",\n" +
                "        \"mobile_visible\": true,\n" +
                "        \"name\": \"Yolo\",\n" +
                "        \"open_id\": \"ou_f55cacf3690399a0ad9cb15d4e909325\",\n" +
                "        \"orders\": [\n" +
                "          {\n" +
                "            \"department_id\": \"f5geb5aae223eea9\",\n" +
                "            \"department_order\": 1,\n" +
                "            \"is_primary_dept\": true,\n" +
                "            \"user_order\": 0\n" +
                "          }\n" +
                "        ],\n" +
                "        \"status\": {\n" +
                "          \"is_activated\": true,\n" +
                "          \"is_exited\": false,\n" +
                "          \"is_frozen\": false,\n" +
                "          \"is_resigned\": false,\n" +
                "          \"is_unjoin\": false\n" +
                "        },\n" +
                "        \"union_id\": \"on_311049e2878178292d80dcb38c7bc960\",\n" +
                "        \"user_id\": \"222agdcf\",\n" +
                "        \"work_station\": \"\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"avatar\": {\n" +
                "          \"avatar_240\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_a1d475f4-4867-4f30-a375-375c260cb14g~?image_size=240x240&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_640\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_a1d475f4-4867-4f30-a375-375c260cb14g~?image_size=640x640&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_72\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_a1d475f4-4867-4f30-a375-375c260cb14g~?image_size=72x72&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_origin\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_a1d475f4-4867-4f30-a375-375c260cb14g~?image_size=noop&cut_type=&quality=&format=png&sticker_format=.webp\"\n" +
                "        },\n" +
                "        \"city\": \"\",\n" +
                "        \"country\": \"\",\n" +
                "        \"department_ids\": [\n" +
                "          \"f5geb5aae223eea9\"\n" +
                "        ],\n" +
                "        \"description\": \"\",\n" +
                "        \"email\": \"\",\n" +
                "        \"employee_no\": \"\",\n" +
                "        \"employee_type\": 1,\n" +
                "        \"en_name\": \"\",\n" +
                "        \"enterprise_email\": \"nana@hpznt.com\",\n" +
                "        \"gender\": 0,\n" +
                "        \"is_tenant_manager\": false,\n" +
                "        \"job_title\": \"\",\n" +
                "        \"join_time\": 0,\n" +
                "        \"mobile\": \"+8615308342615\",\n" +
                "        \"mobile_visible\": true,\n" +
                "        \"name\": \"Nana\",\n" +
                "        \"open_id\": \"ou_5b2e943da0d63ed394f685aabe9fbdad\",\n" +
                "        \"orders\": [\n" +
                "          {\n" +
                "            \"department_id\": \"f5geb5aae223eea9\",\n" +
                "            \"department_order\": 1,\n" +
                "            \"is_primary_dept\": true,\n" +
                "            \"user_order\": 0\n" +
                "          }\n" +
                "        ],\n" +
                "        \"status\": {\n" +
                "          \"is_activated\": true,\n" +
                "          \"is_exited\": false,\n" +
                "          \"is_frozen\": false,\n" +
                "          \"is_resigned\": false,\n" +
                "          \"is_unjoin\": false\n" +
                "        },\n" +
                "        \"union_id\": \"on_75687832572a61cc7c9ada1b8a03e25e\",\n" +
                "        \"user_id\": \"ece77b9d\",\n" +
                "        \"work_station\": \"\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"avatar\": {\n" +
                "          \"avatar_240\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_950c37b6-a504-45d3-ba9c-ceec8f5f7f0g~?image_size=240x240&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_640\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_950c37b6-a504-45d3-ba9c-ceec8f5f7f0g~?image_size=640x640&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_72\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_950c37b6-a504-45d3-ba9c-ceec8f5f7f0g~?image_size=72x72&cut_type=&quality=&format=png&sticker_format=.webp\",\n" +
                "          \"avatar_origin\": \"https://s1-imfile.feishucdn.com/static-resource/v1/v2_950c37b6-a504-45d3-ba9c-ceec8f5f7f0g~?image_size=noop&cut_type=&quality=&format=png&sticker_format=.webp\"\n" +
                "        },\n" +
                "        \"city\": \"\",\n" +
                "        \"country\": \"\",\n" +
                "        \"department_ids\": [\n" +
                "          \"f5geb5aae223eea9\"\n" +
                "        ],\n" +
                "        \"description\": \"\",\n" +
                "        \"email\": \"\",\n" +
                "        \"employee_no\": \"\",\n" +
                "        \"employee_type\": 1,\n" +
                "        \"en_name\": \"\",\n" +
                "        \"enterprise_email\": \"leo@hpznt.com\",\n" +
                "        \"gender\": 0,\n" +
                "        \"is_tenant_manager\": false,\n" +
                "        \"job_title\": \"\",\n" +
                "        \"join_time\": 0,\n" +
                "        \"mobile\": \"+8613541396713\",\n" +
                "        \"mobile_visible\": true,\n" +
                "        \"name\": \"Leo\",\n" +
                "        \"open_id\": \"ou_b56984e619f8a60913444e518f020e01\",\n" +
                "        \"orders\": [\n" +
                "          {\n" +
                "            \"department_id\": \"f5geb5aae223eea9\",\n" +
                "            \"department_order\": 1,\n" +
                "            \"is_primary_dept\": true,\n" +
                "            \"user_order\": 0\n" +
                "          }\n" +
                "        ],\n" +
                "        \"status\": {\n" +
                "          \"is_activated\": true,\n" +
                "          \"is_exited\": false,\n" +
                "          \"is_frozen\": false,\n" +
                "          \"is_resigned\": false,\n" +
                "          \"is_unjoin\": false\n" +
                "        },\n" +
                "        \"union_id\": \"on_9f340696970a8785f75dd1c944a5280a\",\n" +
                "        \"user_id\": \"17ec9f12\",\n" +
                "        \"work_station\": \"\"\n" +
                "      }\n" +
                "    ]\n" +
                "  },\n" +
                "  \"msg\": \"success\"\n" +
                "}";
        JSONObject jsonObject = JSON.parseObject(json);
        JSONObject data = jsonObject.getJSONObject("data");
        JSONArray items = data.getJSONArray("items");

        Map<String, String> map = items.stream().collect(Collectors.toMap(e -> JSONObject.class.cast(e).getString("name"),
                e -> JSONObject.class.cast(e).getString("mobile").replaceAll("\\+86", "")));

        String template = "%s(\"%s\")";
        System.out.println(map.entrySet()
                .stream()
                .map(e -> String.format(template, e.getKey(), e.getValue()))
                .collect(Collectors.joining(",")));
    }

}
